//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS CloudFrontKeyValueStore service.
///
/// Amazon CloudFront KeyValueStore Service to View and Update Data in a KVS Resource
public struct CloudFrontKeyValueStore: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the CloudFrontKeyValueStore client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - region: Region of server you want to communicate with. This will override the partition parameter.
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        region: SotoCore.Region? = nil,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: region,
            partition: region?.partition ?? partition,
            serviceName: "CloudFrontKeyValueStore",
            serviceIdentifier: "cloudfront-keyvaluestore",
            serviceProtocol: .restjson,
            apiVersion: "2022-07-26",
            endpoint: endpoint,
            errorType: CloudFrontKeyValueStoreErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }





    // MARK: API Calls

    /// Deletes the key value pair specified by the key.
    @Sendable
    @inlinable
    public func deleteKey(_ input: DeleteKeyRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> DeleteKeyResponse {
        try await self.client.execute(
            operation: "DeleteKey", 
            path: "/key-value-stores/{KvsARN}/keys/{Key}", 
            httpMethod: .DELETE, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Deletes the key value pair specified by the key.
    ///
    /// Parameters:
    ///   - ifMatch: The current version (ETag) of the Key Value Store that you are deleting keys from, which you can get using DescribeKeyValueStore.
    ///   - key: The key to delete.
    ///   - kvsARN: The Amazon Resource Name (ARN) of the Key Value Store.
    ///   - logger: Logger use during operation
    @inlinable
    public func deleteKey(
        ifMatch: String,
        key: String,
        kvsARN: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> DeleteKeyResponse {
        let input = DeleteKeyRequest(
            ifMatch: ifMatch, 
            key: key, 
            kvsARN: kvsARN
        )
        return try await self.deleteKey(input, logger: logger)
    }

    /// Returns metadata information about Key Value Store.
    @Sendable
    @inlinable
    public func describeKeyValueStore(_ input: DescribeKeyValueStoreRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> DescribeKeyValueStoreResponse {
        try await self.client.execute(
            operation: "DescribeKeyValueStore", 
            path: "/key-value-stores/{KvsARN}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Returns metadata information about Key Value Store.
    ///
    /// Parameters:
    ///   - kvsARN: The Amazon Resource Name (ARN) of the Key Value Store.
    ///   - logger: Logger use during operation
    @inlinable
    public func describeKeyValueStore(
        kvsARN: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> DescribeKeyValueStoreResponse {
        let input = DescribeKeyValueStoreRequest(
            kvsARN: kvsARN
        )
        return try await self.describeKeyValueStore(input, logger: logger)
    }

    /// Returns a key value pair.
    @Sendable
    @inlinable
    public func getKey(_ input: GetKeyRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> GetKeyResponse {
        try await self.client.execute(
            operation: "GetKey", 
            path: "/key-value-stores/{KvsARN}/keys/{Key}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Returns a key value pair.
    ///
    /// Parameters:
    ///   - key: The key to get.
    ///   - kvsARN: The Amazon Resource Name (ARN) of the Key Value Store.
    ///   - logger: Logger use during operation
    @inlinable
    public func getKey(
        key: String,
        kvsARN: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetKeyResponse {
        let input = GetKeyRequest(
            key: key, 
            kvsARN: kvsARN
        )
        return try await self.getKey(input, logger: logger)
    }

    /// Returns a list of key value pairs.
    @Sendable
    @inlinable
    public func listKeys(_ input: ListKeysRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ListKeysResponse {
        try await self.client.execute(
            operation: "ListKeys", 
            path: "/key-value-stores/{KvsARN}/keys", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Returns a list of key value pairs.
    ///
    /// Parameters:
    ///   - kvsARN: The Amazon Resource Name (ARN) of the Key Value Store.
    ///   - maxResults: Maximum number of results that are returned per call. The default is 10 and maximum allowed page is 50.
    ///   - nextToken: If nextToken is returned in the response, there are more results available. Make the next call using the returned token to retrieve the next page.
    ///   - logger: Logger use during operation
    @inlinable
    public func listKeys(
        kvsARN: String,
        maxResults: Int? = nil,
        nextToken: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListKeysResponse {
        let input = ListKeysRequest(
            kvsARN: kvsARN, 
            maxResults: maxResults, 
            nextToken: nextToken
        )
        return try await self.listKeys(input, logger: logger)
    }

    /// Creates a new key value pair or replaces the value of an existing key.
    @Sendable
    @inlinable
    public func putKey(_ input: PutKeyRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> PutKeyResponse {
        try await self.client.execute(
            operation: "PutKey", 
            path: "/key-value-stores/{KvsARN}/keys/{Key}", 
            httpMethod: .PUT, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Creates a new key value pair or replaces the value of an existing key.
    ///
    /// Parameters:
    ///   - ifMatch: The current version (ETag) of the Key Value Store that you are putting keys into, which you can get using DescribeKeyValueStore.
    ///   - key: The key to put.
    ///   - kvsARN: The Amazon Resource Name (ARN) of the Key Value Store.
    ///   - value: The value to put.
    ///   - logger: Logger use during operation
    @inlinable
    public func putKey(
        ifMatch: String,
        key: String,
        kvsARN: String,
        value: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> PutKeyResponse {
        let input = PutKeyRequest(
            ifMatch: ifMatch, 
            key: key, 
            kvsARN: kvsARN, 
            value: value
        )
        return try await self.putKey(input, logger: logger)
    }

    /// Puts or Deletes multiple key value pairs in a single, all-or-nothing operation.
    @Sendable
    @inlinable
    public func updateKeys(_ input: UpdateKeysRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> UpdateKeysResponse {
        try await self.client.execute(
            operation: "UpdateKeys", 
            path: "/key-value-stores/{KvsARN}/keys", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Puts or Deletes multiple key value pairs in a single, all-or-nothing operation.
    ///
    /// Parameters:
    ///   - deletes: List of keys to delete.
    ///   - ifMatch: The current version (ETag) of the Key Value Store that you are updating keys of, which you can get using DescribeKeyValueStore.
    ///   - kvsARN: The Amazon Resource Name (ARN) of the Key Value Store.
    ///   - puts: List of key value pairs to put.
    ///   - logger: Logger use during operation
    @inlinable
    public func updateKeys(
        deletes: [DeleteKeyRequestListItem]? = nil,
        ifMatch: String,
        kvsARN: String,
        puts: [PutKeyRequestListItem]? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> UpdateKeysResponse {
        let input = UpdateKeysRequest(
            deletes: deletes, 
            ifMatch: ifMatch, 
            kvsARN: kvsARN, 
            puts: puts
        )
        return try await self.updateKeys(input, logger: logger)
    }
}

extension CloudFrontKeyValueStore {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: CloudFrontKeyValueStore, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}

// MARK: Paginators

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension CloudFrontKeyValueStore {
    /// Return PaginatorSequence for operation ``listKeys(_:logger:)``.
    ///
    /// - Parameters:
    ///   - input: Input for operation
    ///   - logger: Logger used for logging
    @inlinable
    public func listKeysPaginator(
        _ input: ListKeysRequest,
        logger: Logger = AWSClient.loggingDisabled
    ) -> AWSClient.PaginatorSequence<ListKeysRequest, ListKeysResponse> {
        return .init(
            input: input,
            command: self.listKeys,
            inputKey: \ListKeysRequest.nextToken,
            outputKey: \ListKeysResponse.nextToken,
            logger: logger
        )
    }
    /// Return PaginatorSequence for operation ``listKeys(_:logger:)``.
    ///
    /// - Parameters:
    ///   - kvsARN: The Amazon Resource Name (ARN) of the Key Value Store.
    ///   - maxResults: Maximum number of results that are returned per call. The default is 10 and maximum allowed page is 50.
    ///   - logger: Logger used for logging
    @inlinable
    public func listKeysPaginator(
        kvsARN: String,
        maxResults: Int? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) -> AWSClient.PaginatorSequence<ListKeysRequest, ListKeysResponse> {
        let input = ListKeysRequest(
            kvsARN: kvsARN, 
            maxResults: maxResults
        )
        return self.listKeysPaginator(input, logger: logger)
    }
}

extension CloudFrontKeyValueStore.ListKeysRequest: AWSPaginateToken {
    @inlinable
    public func usingPaginationToken(_ token: String) -> CloudFrontKeyValueStore.ListKeysRequest {
        return .init(
            kvsARN: self.kvsARN,
            maxResults: self.maxResults,
            nextToken: token
        )
    }
}
